package com.unswift.cloud.adapter.issue.environment;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.unswift.annotation.api.Api;
import com.unswift.annotation.api.ApiField;
import com.unswift.annotation.api.ApiMethod;
import com.unswift.cloud.adapter.BaseAdapter;
import com.unswift.cloud.mapper.issue.environment.IssueEnvironmentExtendMapper;
import com.unswift.cloud.mapper.issue.environment.IssueEnvironmentMapper;
import com.unswift.cloud.pojo.dao.issue.environment.IssueEnvironmentDataDo;
import com.unswift.cloud.pojo.dao.issue.environment.IssueEnvironmentSearchDo;
import com.unswift.cloud.pojo.dao.issue.environment.IssueEnvironmentSingleDo;
import com.unswift.cloud.sql.issue.environment.IssueEnvironmentSql;
import com.unswift.utils.ExceptionUtils;
import com.unswift.utils.ObjectUtils;

@Component
@Api(value="发布环境公共服务-此bean可以被任何Service引用", author="liyunlong", date="2024-04-16", version="1.0.0")
public class IssueEnvironmentAdapter extends BaseAdapter{
	
	@Autowired
	@ApiField("发布环境数据库操作对象")
	private IssueEnvironmentMapper issueEnvironmentMapper;
	
	@Autowired
	@ApiField("发布环境自定义sql")
	private IssueEnvironmentSql issueEnvironmentSql;
	
	@Autowired
	@ApiField("发布环境数据库扩展操作对象")
	private IssueEnvironmentExtendMapper issueEnvironmentExtendMapper;
	
	@ApiMethod(value="获取发布环境数据库操作对象", returns=@ApiField("数据库操作对象"))
	public IssueEnvironmentMapper getMapper(){
		return issueEnvironmentMapper;
	}
	
	@ApiMethod(value="获取发布环境模块名称", returns=@ApiField("模块名称"))
	public String getModule(){
		return "issueEnvironment";
	}
	
	@ApiMethod(value="根据主键查询单个对象", params=@ApiField("主键"), returns=@ApiField("主键匹配的对象"))
	public IssueEnvironmentDataDo findById(Long id){
		return this.findSingle(new IssueEnvironmentSingleDo(id, null));
	}
	
	@ApiMethod(value="根据主键列表查询列表对象", params=@ApiField("主键列表"), returns=@ApiField("主键列表匹配的列表对象"))
	public List<IssueEnvironmentDataDo> findByIds(List<Long> idList){
		return this.findList(new IssueEnvironmentSearchDo(idList));
	}
	
	@ApiMethod(value="根据查询对象查询首个对象", params={@ApiField("查询对象"), @ApiField("查询到多个是否抛出异常，可以传入指定提示语，如果提示语为空，则不提示，总的提示与格式：根据%s查询到多条数据，只需要传递%s部分即可")}, returns=@ApiField("首个对象"))
	public IssueEnvironmentDataDo findFirst(IssueEnvironmentSearchDo search, String multipleException){
		List<IssueEnvironmentDataDo> list=this.findList(search);
		if(ObjectUtils.isEmpty(list)){
			return null;
		}
		if(ObjectUtils.isNotEmpty(multipleException)){
			ExceptionUtils.trueException(list.size()>1, "multiple.data.found", multipleException);
		}
		return list.get(0);
	}
}
